package com.zhkj.txg.module.find.model

import com.zhkj.lib.http.BaseManager
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.ResponseSubscribeListener
import com.zhkj.lib.http.SubscribeListener
import com.zhkj.txg.module.find.entity.*
import io.reactivex.disposables.Disposable

class FindManager(clazz: Class<FindApi>) : BaseManager<FindApi>(clazz) {
    /**
     * 获取发现分页列表
     */
    fun findList(
        token: String,
        page: Int,
        numb: Int,
        listener: SubscribeListener<FindListResponse>
    ): Disposable {
        val findList = apiService.findList(token, page, numb)
        return subscribe(findList, ResponseSubscribeListener(listener))
    }

    /**
     * 获取发现页详情
     */
    fun findDetail(
        token: String,
        id: Int,
        listener: SubscribeListener<FindArticleResponse>
    ): Disposable {
        val findArticleDetail = apiService.findArticleDetail(token, id)
        return subscribe(findArticleDetail, ResponseSubscribeListener(listener))
    }

    /**
     * 获取发现文章评论列表
     */
    fun findArticleCommentList(
        token: String,
        id: Int,
        page: Int,
        numb: Int,
        listener: SubscribeListener<FindCommentResponse>
    ): Disposable {
        val commentList = apiService.findArticleCommentList(token, id, page, numb)
        return subscribe(commentList, ResponseSubscribeListener(listener))
    }

    /**
     * 提交评论
     */
    fun commentCommit(
        token: String,
        id: Int,
        commentId: Int,
        content: String,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val commentCommit = apiService.commentCommit(token, id, commentId, content)
        return subscribe(commentCommit, ResponseSubscribeListener(listener))
    }

    /**
     * 收藏/取消收藏
     */
    fun likeFind(
        token: String,
        id: Int,
        commentId: Int,
        type: Int,
        listener: SubscribeListener<BaseLikeResponse>
    ): Disposable {
        val likeFind = apiService.likeFind(token, id, commentId, type)
        return subscribe(likeFind, ResponseSubscribeListener(listener))
    }

    /**
     * 删除评论
     */
    fun deleteComment(
        token: String,
        id: Int,
        commentId: Int,
        listener: SubscribeListener<BaseLikeResponse>
    ): Disposable {
        val deleteComment = apiService.deleteComment(token, id, commentId)
        return subscribe(deleteComment, ResponseSubscribeListener(listener))
    }

    /**
     * 获取可关联商品列表
     */
    fun associateProductList(
        token: String,
        page: Int,
        numb: Int,
        searchKey: String,
        listener: SubscribeListener<AssociateProductResponse>
    ): Disposable {
        val productList = apiService.associateProductList(token, page, numb, searchKey)
        return subscribe(productList, ResponseSubscribeListener(listener))
    }

    /**
     * 发表发现文章
     */
    fun publishArticle(
        token: String,
        content: String,
        images: String,
        goodsId: Long,
        listener: SubscribeListener<BaseResponse>
    ): Disposable {
        val publishArticle = apiService.publishArticle(token, content, images, goodsId)
        return subscribe(publishArticle, ResponseSubscribeListener(listener))
    }
}